import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;
//提供反转字符串的客户端
public class TcpC {
    public static void main(String[] args) throws Exception{
        
    
       Socket client=new Socket("127.0.0.1",8888);
        System.out.println("客户端："+client);
        InputStream is=client.getInputStream();
        OutputStream os=client.getOutputStream();
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入要反转的字符串：");

        String input=scanner.nextLine();

        String reversed=new StringBuilder(input).reverse().toString();
        String string=reversed;
        byte[] b=string.getBytes();
        //将数组写到输出流
        os.write(b);
        byte[] b2=new byte[1024];
        int length=is.read(b2);
        if(length!=-1){
            System.out.println(new String(b2,0,length));
        }
         //关闭资源
         scanner.close();
         os.close();
         is.close();
         client.close();
}
}
